package com.example.toutiao.ui.fragment;

import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import com.example.toutiao.db.CartItem;

import java.util.List;

public class CheckoutDialogFragment extends DialogFragment {

    private List<CartItem> cartItems;
    private double totalAmount;

    public CheckoutDialogFragment(List<CartItem> cartItems, double totalAmount) {
        this.cartItems = cartItems;
        this.totalAmount = totalAmount;
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle("结算确认")
                .setMessage("总金额: ￥" + totalAmount)
                .setPositiveButton("确认购买", (dialog, which) -> {
                    Toast.makeText(getContext(), "购买成功", Toast.LENGTH_SHORT).show();
                    cartItems.clear();
                })
                .setNegativeButton("取消", (dialog, which) -> {
                });

        return builder.create();
    }
}

